package leetcode.medium.limit50;

import java.util.Arrays;

/**
 * @author yaoyao1.liu@zhaopin.com.cn
 * @since 2022-11-09 14:48
 **/
public class No48 {
    public static void main(String[] args) {
        No48 no48 = new No48();
        int[][] m = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        no48.rotate(m);
        System.out.println(Arrays.deepToString(m));


    }

    public void rotate(int[][] matrix) {

        int length = matrix.length;
        int[][] newMa = new int[length][length];
        for (int x = 0; x < length; x++) {
            int[] yMatrix = matrix[x];
            int yLength = yMatrix.length;
            for (int y = 0; y < yLength; y++) {
                int newX = length - 1 - y;
                int newY = x;
                newMa[x][y] = matrix[newX][newY];
            }
        }

        for (int x = 0; x < length; x++) {
            int[] yMatrix = matrix[x];
            int yLength = yMatrix.length;
            for (int y = 0; y < yLength; y++) {
                matrix[x][y] = newMa[x][y];
            }
        }
    }
}
